package com.qdhh.enrollment.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qdhh.enrollment.common.Result;
import com.qdhh.enrollment.model.Student;
import com.qdhh.enrollment.service.AdminUserManagementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员用户管理控制器
 */
@Tag(name = "管理员用户管理", description = "用户列表、状态管理接口")
@RestController
@RequestMapping("/api/admin/users")
public class AdminUserManagementController {

    private final AdminUserManagementService adminUserManagementService;

    public AdminUserManagementController(AdminUserManagementService adminUserManagementService) {
        this.adminUserManagementService = adminUserManagementService;
    }

    @Operation(summary = "分页查询用户列表")
    @GetMapping
    public Result<Page<Student>> listUsers(
            @Parameter(description = "页码") @RequestParam(defaultValue = "1") int page,
            @Parameter(description = "每页数量") @RequestParam(defaultValue = "10") int size,
            @Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword) {
        Page<Student> result = adminUserManagementService.listUsers(page, size, keyword);
        return Result.success(result);
    }

    @Operation(summary = "根据ID获取用户")
    @GetMapping("/{id}")
    public Result<Student> getUserById(@PathVariable String id) {
        Student user = adminUserManagementService.getUserById(id);
        return Result.success(user);
    }

    @Operation(summary = "更新用户状态")
    @PutMapping("/{id}/status")
    public Result<Void> updateUserStatus(
            @PathVariable String id,
            @RequestBody StatusRequest request) {
        adminUserManagementService.updateUserStatus(id, request.getStatus());
        return Result.success("更新成功", null);
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/{id}")
    public Result<Void> deleteUser(@PathVariable String id) {
        adminUserManagementService.deleteUser(id);
        return Result.success("删除成功", null);
    }

    public static class StatusRequest {
        private Integer status;

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }
    }
}

